|
|
|
|
|
|
|
Variants take up a significant amount of memory compared to normal data types. In addition, they are very slow to retrieve and get values. Because these requirements can slow down your application, you should use normal data types instead of variants whenever possible. Table 6.5 shows you the different data types a variant can store. |
|
|
|
|
| Table 6.5 Variant Data Types. | | Data Type | Description | | Empty | Declared but not yet initialized. | | Null | Special data type used with database applications. | | Object | Special data type that will be covered in Chapters 1921. | | Integer | Normal data type. | | Long | Normal data type. | | Single | Normal data type. | | Double | Normal data type. | | Currency | Normal data type. | | Date | Normal data type. Date and/or Time variable. | | String | Normal data type. | | Boolean | Normal data type. |
|
|
|
|
|
|
As you can see from the table, all the normal data types are accounted for, plus two additional types. The first type, Empty, is a special type thats used to initialize the variant when its declared. Just like an Integer data type is initialized to 0 and a string to "", a Variant data type is initialized to Empty. The other type is Null. A Null is a special value thats returned from a column in a table when no data is stored in that column. Whenever you retrieve data from a table, you need to store that data in a variant first, test it for Null, and then convert it into the data type you want. |
|
|
|
|
|
|
|
|
Lets look at some code to see how to use the Variant data type: |
|
|
|
 |
|
|
|
|
Dim vntVariable As Variant
vntVariable = 10
...
... |
|
|
|
|
|